home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / GUSI / include / GUSI.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-07  |  7.0 KB  |  266 lines  |  [TEXT/MPS ]

  1. /*********************************************************************
  2. Project    :    GUSI                -    Grand Unified Socket Interface
  3. File        :    GUSI.h            -    Socket calls
  4. Author    :    Matthias Neeracher
  5. Started    :    21Mar92                                Language    :    MPW C/C++
  6. Modified    :    17Apr92    MN    bzero()
  7.                 19Apr92    MN    C++ compatibility
  8.                 27Apr92    MN    getsockopt()
  9.                 18May92    MN    PPC stuff
  10.                 26Jun92    MN    choose()
  11.                 21Jul92    MN    sockaddr_atlk_sym
  12.                 03Aug92    MN    sa_constr_ppc
  13.                 07Sep92    MN    readlink()
  14.                 12Sep92    MN    Hostname stuff
  15.                 26Sep92    MN    Separate dirent and stat
  16.                 15Nov92    MN    remove netdb.h definitions
  17.                 08Dec92    MN    getcwd()
  18.                 14Feb93    MN    AF_PAP
  19.                 20Jun93    MN    Changed sa_constr_ppc
  20.                 27Jun93    MN    f?truncate
  21. Last        :    27Jun93
  22. *********************************************************************/
  23.  
  24. #ifndef _GUSI_
  25. #define _GUSI_
  26.  
  27. #include <sys/types.h>
  28.  
  29. /* Feel free to increase FD_SETSIZE as needed */
  30. #define GUSI_MAX_FD    FD_SETSIZE
  31.  
  32. #include <sys/cdefs.h>
  33. #include <compat.h>
  34. #include <sys/ioctl.h>
  35. #include <sys/fcntl.h>
  36. #include <sys/stat.h>
  37. #include <dirent.h>
  38. #include <Types.h>
  39. #include <Events.h>
  40. #include <Files.h>
  41. #include <AppleTalk.h>
  42. #include <CTBUtilities.h>
  43. #include <Packages.h>
  44. #include <PPCToolBox.h>
  45. #include <sys/time.h>
  46. #include <sys/socket.h>
  47. #include <string.h>
  48. #include <netinet/in.h>
  49. #include <netdb.h>
  50. #include <sys/un.h>
  51. #include <unistd.h>
  52. #include <machine/endian.h>
  53.  
  54. typedef enum spin_msg {
  55.     SP_MISC,                /* some weird thing, usually just return immediately if you get this */
  56.     SP_SELECT,            /* in a select call */
  57.     SP_NAME,                /* getting a host by name */
  58.     SP_ADDR,                /* getting a host by address */
  59.     SP_STREAM_READ,    /* Stream read call */
  60.     SP_STREAM_WRITE,    /* Stream write call */
  61.     SP_DGRAM_READ,        /* Datagram read call */
  62.     SP_DGRAM_WRITE,    /* Datagram write call */
  63.     SP_SLEEP,            /* sleeping, passes ticks left to sleep */
  64.     SP_AUTO_SPIN        /* Autospin, passes argument to SpinCursor */
  65. } spin_msg;
  66.  
  67. typedef int (*GUSISpinFn)(spin_msg msg, long param);
  68. typedef void (*GUSIEvtHandler)(EventRecord * ev);
  69. typedef GUSIEvtHandler    GUSIEvtTable[24];
  70.  
  71. /*
  72.  * Address families, defined in sys/socket.h
  73.  *
  74.  
  75. #define    AF_UNSPEC         0        // unspecified
  76. #define    AF_UNIX             1        // local to host (pipes, portals)
  77. #define    AF_INET             2        // internetwork: UDP, TCP, etc.
  78. #define    AF_CTB             3        // Apple Comm Toolbox (not yet supported)
  79. #define    AF_FILE             4        // Normal File I/O (used internally)
  80. #define    AF_PPC             5        // PPC Toolbox
  81. #define    AF_PAP             6        // Printer Access Protocol (client only)
  82. #define    AF_REMOTECON     7        // Remote Console (used internally)
  83. #define    AF_APPLETALK    16        // Apple Talk
  84.  
  85. */
  86.  
  87. #define    ATALK_SYMADDR 272        /* Symbolic Address for AppleTalk             */
  88.  
  89. /*
  90.  * Types,  defined in sys/socket.h
  91.  *
  92.  
  93. #define    SOCK_STREAM         1        // stream socket 
  94. #define    SOCK_DGRAM         2        // datagram socket
  95.  
  96. */
  97.  
  98. /*
  99.  * Defined in sys/un.h
  100.  *
  101.  
  102. struct sockaddr_un {
  103.     short        sun_family;
  104.     char         sun_path[108];
  105. };
  106.  
  107. */
  108.  
  109. struct sockaddr_atlk {
  110.     short            family;
  111.     AddrBlock    addr;
  112. };
  113.  
  114. struct sockaddr_atlk_sym {
  115.     short            family;
  116.     EntityName    name;
  117. };
  118.  
  119. struct sockaddr_ppc {
  120.     short                    family;
  121.     LocationNameRec    location;
  122.     PPCPortRec            port;
  123. };
  124.  
  125. /* Definitions for choose() */
  126.  
  127. #define     CHOOSE_DEFAULT    1        /*    Use *name as default name                        */
  128. #define    CHOOSE_NEW        2        /* Choose new entity name, not existing one    */
  129. #define    CHOOSE_DIR        4        /* Choose a directory name, not a file         */
  130.  
  131. typedef struct {
  132.     short            numTypes;
  133.     SFTypeList    types;
  134. } sa_constr_file;
  135.  
  136. typedef struct {
  137.     short            numTypes;
  138.     NLType        types;
  139. } sa_constr_atlk;
  140.  
  141. /* Definitions for sa_constr_ppc */
  142.  
  143. #define PPC_CON_NEWSTYLE        0x8000    /* Required */
  144. #define PPC_CON_MATCH_NAME        0x0001    /* Match name */
  145. #define PPC_CON_MATCH_TYPE     0x0002     /* Match port type */
  146. #define PPC_CON_MATCH_NBP        0x0004    /* Match NBP type */
  147.  
  148. typedef struct    {
  149.     short            flags;
  150.     Str32            nbpType;
  151.     PPCPortRec    match;
  152. } sa_constr_ppc;
  153.  
  154. __BEGIN_DECLS
  155. /* 
  156.  * IO/Socket stuff, defined elsewhere (unistd.h, sys/socket.h
  157.  *
  158.  
  159. int socket(int domain, int type, short protocol);
  160. int bind(int s, void *name, int namelen);
  161. int connect(int s, void *addr, int addrlen);
  162. int listen(int s, int qlen);
  163. int accept(int s, void *addr, int *addrlen);
  164. int close(int s);
  165. int read(int s, char *buffer, unsigned buflen);
  166. int readv(int s, struct iovec *iov, int count);
  167. int recv(int s, void *buffer, int buflen, int flags);
  168. int recvfrom(int s, void *buffer, int buflen, int flags, void *from, int *fromlen);
  169. int recvmsg(int s,struct msghdr *msg,int flags);
  170. int write(int s, const char *buffer, unsigned buflen);
  171. int writev(int s, struct iovec *iov, int count);
  172. int send(int s, void *buffer, int buflen, int flags);
  173. int sendto (int s, void *buffer, int buflen, int flags, void *to, int tolen);
  174. int sendmsg(int s,struct msghdr *msg,int flags);
  175. int select(int width, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
  176. int getdtablesize(void);
  177. int getsockname(int s, void *name, int *namelen);
  178. int getpeername(int s, struct sockaddr *name, int *namelen);
  179. int shutdown(int s, int how);
  180. int fcntl(int s, unsigned int cmd, int arg);
  181. int dup(int s);
  182. int dup2(int s, int s1);
  183. int ioctl(int d, unsigned int request, long *argp);
  184. int getsockopt(int s, int level, int optname, char *optval, int * optlen);
  185. int setsockopt(int s, int level, int optname, char *optval, int optlen);
  186. int isatty(int);
  187. int remove(const char *filename);
  188. int rename(const char *oldname, const char *newname);
  189. int creat(const char*);
  190. int faccess(char*, unsigned int, long*);
  191. long lseek(int, long, int);
  192. int open(const char*, int);
  193. int unlink(char*);
  194. int symlink(char* linkto, char* linkname);
  195. int readlink(char* path, char* buf, int bufsiz);
  196. int truncate(char *path, long length);
  197. int ftruncate(int fd, long length);
  198. int chdir(char * path);
  199. int mkdir(char * path);
  200. int rmdir(char * path);
  201. char * getcwd(char * buf, int size);
  202. */
  203.  
  204. /* 
  205.  * Defined in stdio.h
  206.  *
  207.  
  208. void fsetfileinfo (char *filename, unsigned long newcreator, unsigned long newtype);
  209.  
  210. */
  211.  
  212. void fgetfileinfo (char *filename, unsigned long * creator, unsigned long * type);
  213.  
  214. int choose(
  215.         int         domain,
  216.         int         type,
  217.         char *     prompt,
  218.         void *     constraint,
  219.         int         flags,
  220.         void *     name,
  221.         int *     namelen);
  222.  
  223. /* 
  224.  * Hostname routines, defined in netdb.h
  225.  *
  226.  
  227. struct hostent * gethostbyname(char *name);
  228. struct hostent * gethostbyaddr(struct in_addr *addrP, int, int);
  229. int gethostname(char *machname, long buflen);
  230. struct servent * getservbyname (char * name, char * proto);
  231. struct protoent * getprotobyname(char * name);
  232.  
  233. */
  234.  
  235. char * inet_ntoa(struct in_addr inaddr);
  236. struct in_addr inet_addr(char *address);
  237.  
  238. /* 
  239.  * What to do when a routine blocks
  240.  */
  241.  
  242. void GUSISetSpin(GUSISpinFn routine);
  243. GUSISpinFn GUSIGetSpin(void);
  244. int GUSISetEvents(GUSIEvtTable table);
  245. GUSIEvtHandler * GUSIGetEvents(void);
  246.  
  247. extern GUSIEvtHandler    GUSISIOWEvents[];
  248.  
  249. /* Directory Stuff */
  250.  
  251. /* 
  252.  * BSD memory routines, defined in compat.h
  253.  *
  254.  
  255. #define index(a, b)                        strchr(a, b)
  256. #define rindex(a, b)                        strrchr(a, b)
  257. #define bzero(from, len)                 memset(from, 0, len)
  258. #define bcopy(from, to, len)            memcpy(to, from, len)
  259. #define bcmp(s1, s2, len)                memcmp(s1, s2, len)
  260. #define bfill(from, len, x)            memset(from, x, len)
  261.  
  262.  */
  263.  
  264. __END_DECLS
  265.  
  266. #endif /* !_GUSI_ */